package com.heima.home.controller;

import com.heima.home.dto.BookingListItemDTO;
import com.heima.home.entity.Bookings;
import com.heima.home.entity.Reviews;
import com.heima.home.mapper.BookingMapper;
import com.heima.home.service.BookingService;
import com.heima.home.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/bookings")
public class BookingController {
    
    @Autowired
    private BookingService bookingService;
    
    @GetMapping("/{id}")
    public Bookings getBookingById(@PathVariable Integer id) {
        // 验证用户是否有权限查看此预订
        Integer currentUserId = UserContext.getCurrentUserId();
        // 这里应该调用Service层方法，根据ID和用户ID获取预订信息
        Bookings bookings = bookingService.selectBookingById(id);
        // 示例：return bookingService.findByIdAndUserId(id, currentUserId);
        // 目前直接从Mapper获取数据
        return bookings; // 需要完善实际逻辑
    }


    @GetMapping("/my-orders")
    public ResponseEntity<List<BookingListItemDTO>> getMyOrders() {
        Integer currentUserId = UserContext.getCurrentUserId();
        if (currentUserId == null) {
            return ResponseEntity.status(401).build();
        }
        List<BookingListItemDTO> bookings = bookingService.getUserBookings(currentUserId);
        return ResponseEntity.ok(bookings);
    }
}